package com.imooc.business.facade.model;

import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONArray;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @Author Tim
 * @Description:
 * @Version 1.0
 */
@Component
public class OrganFacade {

    private static final String BUSINESS_ID = "businessId";
    private static final String GROUP_IDS = "groupIds";
    private static final String START_TIME = "startTime";
    private static final String END_TIME = "endTime";
    private static final String FORMAT = "yyyy-MM-dd HH:mm:ss";

    /**
     * 接口拉取组织数据
     * @param url
     * @param businessId
     * @param groupIds
     * @param startTime
     * @param endTime
     * @return
     */
    public List<Organ> fetchBusinessOrgan(String url, String businessId, List<String> groupIds,
                                          Date startTime, Date endTime) {
        Map<String, Object> params = new HashMap<>();
        params.put(BUSINESS_ID, businessId);
        params.put(GROUP_IDS, groupIds);
        params.put(START_TIME, DateUtil.format(startTime, FORMAT));
        params.put(END_TIME, DateUtil.format(endTime, FORMAT));

        String s = HttpUtil.get(url, params);
        return JSONArray.parseArray(s, Organ.class);
    }
}
